import darkCssStr from "./darkCssStr";
import { updateThemeColor } from '@/utils/updateThemeColor'
/**
 * 修改主题
 * @param {*} mode 1: 默认模式 2: 暗黑模式 3: 哀悼
 */
export default function changeMode(mode, themeColor) {
	switch (mode) {
		case 1: // 默认模式
			removeMountStyle()
			removeDarkModeStyle(themeColor)
			break;
		case 2: // 暗黑模式
			removeMountStyle()
			addDarkModeStyle()
			break;
		case 3: // 哀悼
			removeDarkModeStyle(themeColor)
			addMountStyle()
			break;
	}

}
// 启动暗黑模式---待处理，需要把相关颜色全换用css变量
export function addDarkModeStyle() {
	updateThemeColor('#000000')
	const html = document.querySelector('html')
	html.classList.add('dark')
	let darkStyleTag = document.getElementById('dark-style')
	if (!darkStyleTag) {
		darkStyleTag = document.createElement('style')
		darkStyleTag.setAttribute('id', 'dark-style')
		document.head.appendChild(darkStyleTag)
	}
	darkStyleTag.innerText = darkCssStr
}
// 移除暗黑模式
function removeDarkModeStyle(themeColor) {
	const html = document.querySelector('html')
	html.classList.remove('dark')
	updateThemeColor(themeColor)
}
// 添加哀悼样式
function addMountStyle() {
	let styleTag = document.getElementById('mourn-style')
	if (!styleTag) {
		styleTag = document.createElement('style')
		styleTag.setAttribute('id', 'mourn-style')
		document.head.appendChild(styleTag)
	}
	styleTag.innerText = `
  body{-webkit-filter: grayscale(100%);}
  html{
		-webkit-filter:grayscale(100%);
		-moz-filter:grayscale(100%);
		-ms-filter:grayscale(100%);
		-o-filter:grayscale(100%);
		filter:grayscale(100%);
		filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)
  }
  *{
		-moz-filter: grayscale(100%);
		-ms-filter: grayscale(100%);
		-o-filter: grayscale(100%);
		filter: gray;
  }
	`
}
// 移除哀悼样式
function removeMountStyle() {
	const styleTag = document.getElementById('mourn-style')
	if(styleTag) {
		styleTag.innerText = ''
	}
}
